package com.demo2.todo.controller;

import com.demo2.todo.model.dto.ShareResponse;
import com.demo2.todo.model.dto.TodoResponse;
import com.demo2.todo.service.ShareService;
import com.demo2.todo.service.TodoService;
import com.demo2.todo.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author evi
 */
@RestController
@RequestMapping("/shares")
@RequiredArgsConstructor
public class ShareController {
    private final ShareService shareService;
    private final TodoService todoService;

    @PostMapping("/todos/{id}")
    public ResponseEntity<ShareResponse> shareTodo(@PathVariable Long id) {
        return ResponseEntity.ok(shareService.createShare(id, SecurityUtils.getCurrentUser()));
    }

    @GetMapping("/{code}")
    public ResponseEntity<TodoResponse> getSharedTodo(@PathVariable String code) {
        return ResponseEntity.ok(shareService.getSharedTodoByCode(code));
    }
}